#include "optionsparser.h"
#include "algos.h"

COptionsParser::COptionsParser(COptionsBase &options, std::string const &comment_start)
        :parser('='), options(options), comment_start(comment_start){}

void COptionsParser::parse(std::string const &str){
    std::string key(""),
                value(""),
				str_copy(str);
	bool    	_continue(true);
	
	trim(str_copy, " \t\n");
	
	//is this comment string
	if(str_copy.compare(0, comment_start.size(), comment_start) == 0)
		return;
	
    parser.parseString(str_copy);
    
    _continue   &=   parser.getElement(key, 0);
    _continue   &=   parser.getTail(1, value);

    trim(key, " \t\n");
    trim(value, " \t\n");

    _continue   &=  !key.empty();
    _continue   &=  !value.empty();

    if(_continue){
        options.set(key, value);
    }
}
